var app = getApp()
import { find as findShop } from '../../../api/shop'
import { list, find } from '../../../api/product'
import { listByShopId } from '../../../api/product'
import { getCart, del, update, add, clear,} from '../../../api/cart'
import {create} from '../../../api/coupon'
const util = require('../../../utils/util.js')
Page({
    data: {
      shopId:"",
      shopdetails:{
        shop:{
          distance:null,
          name:'',
          mchName:''
        },
        couponList:[]
      },
      goods: [
      ], //所有商品
      ads: [],
      loading: false,
      currentCateId: 6905,//默认分类
      cateScrollTop: 0,
      menuScrollIntoView: '',
      cart: [], //购物车
      goodDetailModalVisible: false, //是否饮品详情模态框
      good: {}, //当前饮品
      category: {}, //当前饮品所在分类
      cartPopupVisible: false,
      sizeCalcState: false,
      orderType:'takeout',
      cartInfo:{},
      products:[],
      cartsTotal:0,
      cartShopping:[],
      cartId:'',
      couponType:false,
      timer:null,
      judgeSame:'',
      addCartButton:false,
      navMarginTop:'',
      navigationType:'orderMeal',
      scrollTopId: '',
      cartGoodsNumber:'0',
      cartGoodsPrice:'0',
      disabledPayFlag:true,
      spread:'0',
      scrollTop:'',
      scrollIng:'',
      timeId:null,
    },
    watchProperty: function (method = function () {}, atrrs, value ) {
      var obj = app.globalData;
      Object.defineProperty(obj, atrrs, {
        configurable: true,
        enumerable: true,
        set: function (_value) {
          value = _value;
          method(value);
        },
        get: function () {
          return value;
        }
      })
    },
    onLoad(options) {
        this.getNavMarginTop()
        if(options.id != "" && options.id != null) {
          this.data.shopId = options.id
          this.watchProperty(this.cartInfoRequest,'token')
          this.listByShopId()
          this.findShop()
        }
        if(this.data.shopdetails != undefined){
            this.data.shopdetails.couponList.forEach(function(item) {
                item.endDate =util.datetimeFormat(item.endDate)
              })
          this.setData({
            shopdetails:this.data.shopdetails
          })
        }
    },
    onShow(){
        // let settime = setTimeout(()=>{
        //     if(wx.getStorageSync('returnFlag') == true){
        //             this.data.cart = []
        //             this.setData({
        //                 cart:this.data.cart
        //             })
        //           this.cartInfoRequest()
        //         wx.setStorageSync('returnFlag', false)
        //     }
        //     clearTimeout(settime)
        // },1000)
    },
    getNavMarginTop(){
        let that=this;
        let sysinfo = wx.getSystemInfoSync(),
            statusHeight = sysinfo.statusBarHeight,
            isiOS = sysinfo.system.indexOf('iOS') > -1,
            navHeight
        if (!isiOS) {
            navHeight = 48;
        } else {
            navHeight = 44;
        }
        this.data.navMarginTop = statusHeight +navHeight
        this.setData({
            navMarginTop:this.data.navMarginTop
        })
    },
    // 监听滚动事件
    bindscroll(e){
        clearInterval(this.data.timeId);
        this.data.timeId = setTimeout(() => {
          this.calcSize(e)
          clearInterval(this.data.timeId);
        }, 100);
    },
    calcSize(e) {
        var viewTop = []
        new Promise((resolve, reject) => {
          this.data.goods.forEach((item ,index) => {
            wx.createSelectorQuery().select('#cate-'+item.id ).boundingClientRect( res=> {
              viewTop.push(res.top)
              if(this.data.goods.length == index + 1  ){
                resolve()
              }
            }).exec()
          })
        }).then(() => {
          let viewDifference = [];
          for(let i in viewTop){
            if(i>0){
              viewDifference.push(viewTop[i]-viewTop[0])
            }
          }
          let disFirstRoll = e.target.offsetTop- viewTop[0] + 10
            viewDifference.forEach((item, index) => {
                if (disFirstRoll >= item) {
                    this.data.currentCateId = this.data.goods[index + 1].id
                }
                if (disFirstRoll == 0 || disFirstRoll < viewTop[0]) {
                    this.data.currentCateId = this.data.goods[0].id
                }
            })
            this.setData({
                currentCateId: this.data.currentCateId
            })
        })
    },
    getSpread() { //差多少元起送
      return parseFloat((this.data.shopdetails.shop.minimumDelivery - this.data.cartGoodsPrice).toFixed(2))
    },
    getDisabledPay() { //是否达到起送价
      return this.data.orderType == 'takeout' && (this.data.cartGoodsPrice < this.data.shopdetails.shop.minimumDelivery)
    },
    getCartGoodsPrice() {	//计算购物车总价
      return this.data.cart.reduce((acc, cur) => acc + cur.number * cur.price, 0)
    },
    getCartGoodsNumber() { //计算购物车总数
        console.log(this.data.cart ,"22222222")
        return this.data.cart.reduce(function(a,b){
          return a+b.number;
        },0)
      },
      maskClick(e) {
        let item = e.currentTarget.dataset.item
        if (app.globalData.token == "" || app.globalData.token == null) {
          wx.navigateTo({
            url: '/pages/login/index',
          })
        } else {
          create({couponId: item.id, mchId: item.mchId}).then(res => {
            wx.showToast({
              title: '领取成功',
              icon: 'success',
              duration: 2000
            })
            this.cancleClick()
          }).catch(err=>{this.cancleClick()})
        }
      },
      changeNavigation(e){
        this.data.navigationType = e.currentTarget.dataset.type
        this.setData({
          navigationType:this.data.navigationType
        })
      },
      couponClick() {
        this.data.couponType = true
        this.setData({
          couponType:this.data.couponType
        })
      },
      cancleClick() {
        this.data.couponType = false
        this.setData({
          couponType:this.data.couponType
        })
      },
      findShop(){
        let params = this.data.shopId
        let LongitudeLatitude = {
          lat : this.data.latitude,
          lng : this.data.longitude
        }
        findShop(params,LongitudeLatitude).then(res=>{
          var _this =  this
          if (!util.isNull(res.data.couponList)) {
            res.data.couponList.forEach(function (item) {
              item.endDate =util.datetimeFormat(item.endDate)
              if (item.targetType == 0) {
                item.targetName = '通用券'
              } else if (item.targetType == 1) {
                item.targetName = '品牌券'
              } else if (item.targetType == 2) {
                item.targetName = '会员券'
              } else if (item.targetType == 3) {
                item.targetName = '分类券'
              } else if (item.targetType == 4) {
                item.targetName = '商品券'
              }
              if (item.scope == 0) {
                item.scopeName = '全场'
              } else if (item.scope == 1) {
                item.scopeName = '店内'
              } else if (item.scope == 2) {
                item.scopeName = '商城'
              }
            })
          }
          if(res.data.shop.mchName != ""){
            res.data.shop.mchName = res.data.shop.mchName.substr(0,6)
          }
          if(res.data.shop.name != ""){
            res.data.shop.name = res.data.shop.name.substr(0,6)
          }
          if(res.data.couponList == null){
            res.data.couponList = []
          }
          this.data.shopdetails.shop.doorPhoto = util.thumbnail( res.data.shop.doorPhoto,200,200)
          if(res.data.attachVo == ""){
            res.data.attachVo.scene = ""
            res.data.attachVo.thedoor = ""
          }
          this.data.shopdetails =  res.data
          if(this.data.shopdetails.couponList.length >0){
            this.data.shopdetails.couponList.forEach(item=>{
              item.name = item.name.substring(0, 6)
            })
          }
          this.setData({
            shopdetails:this.data.shopdetails,
          })
          this.data.spread = this.getSpread()
          this.data.disabledPay = this.getDisabledPay()
          this.setData({
            disabledPay:this.data.disabledPay,
            spread:this.data.spread,
          })
        })
      },
      cartInfoRequest() {
        let params = {}
        this.data.cartInfo = []
        params.shopId = this.data.shopId
        getCart(params).then(res => {
          if (res.type == 'success') {
            this.data.cartInfo = res.data.cart.itemVoList
            this.data.cartInfo.forEach(item=>{
              this.data.cart.push({
                id: item.id,
                name: item.name,
                price: item.price,
                number: item.quantity,
                image: item.thumbnail,
                chk: item.chk,
                minLimit:item.minLimit,
                productId:item.productId
              })
            })
            this.data.cartGoodsNumber = this.getCartGoodsNumber()
            this.data.cartGoodsPrice = this.getCartGoodsPrice()
            this.data.spread = this.getSpread()
            this.data.disabledPayFlag = this.getDisabledPay()
            this.setData({
              cartInfo:this.data.cartInfo,
              cart:this.data.cart,
              cartGoodsNumber:this.data.cartGoodsNumber,
              cartGoodsPrice:this.data.cartGoodsPrice,
              spread:this.data.spread,
              disabledPayFlag:this.data.disabledPayFlag
            })
          }
        })
      },
      listByShopId(){
        let params={
          shopId:this.data.shopId,
          pageNum: 1,
          pageSize: 5000,
          sortField:'productCategoryId'
        }
        listByShopId(params).then(res=> {
          if(res.data.data.length == 0){
            this.data.navigationType = 'brand'
            this.setData({
              navigationType: this.data.navigationType
            })
          }
          this.data.goods = []
          let productList = res.data.data
          let productCategoryNameList = []
          productList.forEach(item=>{
            productCategoryNameList.push({
              name:item.productCategoryName,
              id:item.productCategoryId
            })
          })
          let duplicateRemovalproductCategoryNameList = [];
          var obj = {};
          productCategoryNameList.forEach((item,index)=>{
            if(!obj[item.id]){
              duplicateRemovalproductCategoryNameList.push(item);
              obj[item.id]=true;
            }
          });
          duplicateRemovalproductCategoryNameList.forEach(item=>{
            this.data.goods.push({
              name:item.name,
              id:item.id
            })
          })
          this.data.goods.forEach((item,index)=>{
            this.data.goods[index].goods_list = []
            productList.forEach(productListItem =>{
              if(productListItem.productCategoryName == item.name){
                if(productListItem.sku  > 1){
                  productListItem.sku = true
                }else {
                  productListItem.sku = false
                }
                this.data.goods[index].goods_list.push({
                  stock: productListItem.stock,
                  id: productListItem.id,
                  images:productListItem.thumbnail,
                  name:productListItem.name,
                  price:productListItem.price,
                  content:productListItem.subTitle,
                  use_property:productListItem.sku,
                  minLimit:productListItem.minLimit,
                  number: 0,
                  promotions:productListItem.promotions
                })
              }
            })
          })
          this.setData({
            goods:this.data.goods
          })
          this.data.cart.forEach(cartItem=>{
            this.data.goods.forEach(goodsItem=>{
              goodsItem.goods_list.forEach(goodsListitem=>{
                if(goodsListitem.id == cartItem.productId){
                  goodsListitem.number = cartItem.number
                }
              })
            })
          })
        })
      },
      async init() {	//页面初始化
        this.data.loading = true
        await this.getStore()
        this.data.goods = await this.$api('goods')
        this.data.loading = false
        this.data.cart = uni.getStorageSync('cart') || []
      },
      takout(e) {
        this.data.orderType = e
      },
     handleMenuTap(e){
           let id = e.currentTarget.dataset.id
           this.data.scrollTopId = 'cate-'+ id
           this.data.currentCateId = id,
             this.setData({
               scrollTopId:this.data.scrollTopId,
               currentCateId:this.data.currentCateId,
             })
     },
      // handleMenuTap: util.throttle(function(e){
      //     let id = e[0].target.dataset.id
      //     this.data.scrollTopId = 'cate-'+ id
      //     this.data.currentCateId = id,
      //       this.setData({
      //         scrollTopId:this.data.scrollTopId,
      //         currentCateId:this.data.currentCateId,
      //       })
      // },1),
      async  getCart(){
          let params ={
            shopId:this.data.shopId
          }
        await  getCart(params).then(res=>{
          this.data.cartShopping = []
          this.data.cartShopping = res.data.cart.itemVoList
         })
        },
      async handleAddToCart(e) {	//添加到购物车
        let item = e.currentTarget.dataset.item
        let good = e.currentTarget.dataset.good
        let num = e.currentTarget.dataset.num
        let goodsIndex = e.currentTarget.dataset.goodsIndex
        let key = e.currentTarget.dataset.key
        if( util.isNull(app.globalData.token) ){
          wx.navigateTo({
            url: '/pages/login/index',
          })
          return  false
        }
        if(good.stock == 0){
          uni.showToast({
            icon: "none",
            title: '商品已缺货',
          })
          return false
        }
        if(key != null){
          this.data.goods[goodsIndex].goods_list[key].number += num
        }
        await this.addProductToCart(good)
        await this.getCart()
        this.data.cartShopping.forEach(item=>{
          if(item.productId == good.id){
            this.data.cartId = item.id
          }
        })
        const index = this.data.cart.findIndex(item => {
          if(good.use_property > 1) {
            return item.productId == good.id
          }
          else {
            return item.productId == good.id
          }
        })
        if(this.data.cart.length == 0){
          this.data.cartShopping.forEach(item=>{
            if(item.productId == good.id){
              this.data.cartId = item.id
            }
          })
        }
        if(index > -1) {
          this.data.cart[index].number += 1
        }
        else {
            if(good.minLimit == 0){
                good.minLimit =1
            }
          good.number =good.minLimit
          console.log(good.minLimit)
          this.data.cart.push({
            id: this.data.cartId,
            name: good.name,
            price: good.price,
            number: good.minLimit,
            image: good.images,
            productId: good.id,
            use_property: good.use_property,
            cate_id: item.id,
          })
        }
        this.data.cartGoodsPrice = this.getCartGoodsPrice()
        this.data.cartGoodsNumber = this.getCartGoodsNumber()
        this.data.spread = this.getSpread()
        this.data.disabledPayFlag = this.getDisabledPay()
        this.setData({
          cart:this.data.cart,
          cartShopping:this.data.cartShopping,
          cartGoodsNumber:this.data.cartGoodsNumber,
          cartGoodsPrice:this.data.cartGoodsPrice,
          spread:this.data.spread,
          disabledPay:this.data.disabledPay,
          disabledPayFlag:this.data.disabledPayFlag
        })
      },
      handleReduceFromCart(item, good,goodsIndex,key) {
        const index = this.data.cart.findIndex(item => item.productId == good.id)
        if(this.data.goods[goodsIndex].goods_list[key].number > this.data.goods[goodsIndex].goods_list[key].minLimit ){
  
          this.data.goods[goodsIndex].goods_list[key].number -= 1
        }else {
  
          this.data.goods[goodsIndex].goods_list[key].number = 0
          this.data.cart[index].number = 1
        }
        this.handleCartItemReduce(index,this.data.cart[index])
      },
     async handleCartItemReduce(e) {
      let index = e.currentTarget.dataset.index
       let item = e.currentTarget.dataset.item
       if(this.data.cart[index].number == 1  || this.data.cart[index].number == 0 ||this.data.cart[index].number == item.minLimit ){
        await  this.cartDelete(item)
        }
        if(this.data.cart[index].number > 1  ){
         await this.numReduce(item)
        }
        if(this.data.cart[index].number == 1) {
          this.data.goods.forEach(goodsItem=>{
            goodsItem.goods_list.forEach(goodsListItem=>{
              if(goodsListItem.id == this.data.cart[index].productId ){
                goodsListItem.number = 0
              }
            })
          })
          this.data.cart.splice(index, 1)
        } else {
          this.data.goods.forEach(goodsItem=>{
            goodsItem.goods_list.forEach(goodsListItem=>{
              if(goodsListItem.id == this.data.cart[index].productId ){
              }
            })
          })
          this.data.cart[index].number -= 1
        }
       this.data.cartGoodsPrice = this.getCartGoodsPrice()
       this.data.cartGoodsNumber = this.getCartGoodsNumber()
       this.data.spread = this.getSpread()
       this.data.disabledPayFlag = this.getDisabledPay()
       this.setData({
          goods:this.data.goods,
          cart:this.data.cart,
          cartGoodsPrice:this.data.cartGoodsPrice,
          cartGoodsNumber:this.data.cartGoodsNumber,
          spread:this.data.spread,
          disabledPayFlag:this.data.disabledPayFlag
       })
        if(!this.data.cart.length) {
          this.data.cartPopupVisible = false
          this.selectComponent('#bottomPop').clickme();
        }
      },
     async numReduce(item){
        let params =[{
          chk:true,
          id:item.id,
          quantity:item.number -1,
        }]
       await update(params).then(res => {
        })
      },
     async cartDelete(item) {
        let params = item.id
      await del(params).then(res => {
        })
      },
      async addProductToCart(item) {
        let productId = item.id
        this.data.eInfo = item
        if(item.use_property > 1){
        }else{
          let params = {}
          params.shopId = this.data.shopId
          params.productId = productId
          params.promotionId = ""
          if(item.minLimit == 0){
            params.quantity = 1
          }else {
            let good = item
            const index = this.data.cart.findIndex(item => {
              if(good.use_property > 1) {
                return item.productId == good.id
              }
              else {
                return item.productId == good.id
              }
            })
            if(index > -1) {
              params.quantity = 1
            }else {
              params.quantity = item.minLimit
            }
          }
        await  add(params).then(res => {
                if (res.type == 'success') {
                  wx.showToast({
                    title: '成功加入购物车',
                    duration: 2000,
                    icon:'none'
                  })
                }
              }
          )
        }
      },
      showGoodDetailModal(e) {
        let item = e.currentTarget.dataset.item
        let good = e.currentTarget.dataset.good
        this.data.good = JSON.parse(JSON.stringify({...good, number: 1}))
        this.data.category = JSON.parse(JSON.stringify(item))
        new Promise((resolve, reject) => {
          this.productDetails(good.id,resolve)
        }).then(() => {
          this.data.goodDetailModalVisible = true
          this.setData({
            goodDetailModalVisible:this.data.goodDetailModalVisible
          })
        })
      },
      productDetails(id,resolve) { //请求商品数据
        find(id).then(res => {
          let products = res.data.products
          this.data.products = products
          let specifications = []
          let colour = []
          products.forEach(item=>{
            specifications.push(item.spec1)
            colour.push(item.spec2)
          })
          specifications =Array.from(new Set(specifications));
          colour =Array.from(new Set(colour));
          this.data.good.property = [
            {name:"规格",values:[]},
            {name:"颜色",values:[]}
          ]
          this.data.good.property.forEach(item=>{
            if(item.name == '规格'){
              specifications.forEach(specificationsItem=>{
                if(specificationsItem != ""){
                  item.values.push({value:specificationsItem})
                }
              })
            }
            if(item.name == '颜色'){
              colour.forEach(colourItem=>{
                if(colourItem != ""){
                  item.values.push({value:colourItem})
                }
              })
            }
          })
          this.data.good.property.forEach((item ,index)=>{
            if(item.values.length == 0){
              this.data.good.property.splice(index,1);
            }
          })
          this.setData({
            good:this.data.good
          })
          resolve()
        })
      },
      closeGoodDetailModal() { //关闭饮品详情模态框
        this.data.goodDetailModalVisible = false
        this.data.category = {}
        this.data.good = {}
        this.setData({
          goodDetailModalVisible:this.data.goodDetailModalVisible,
          category:this.data.category,
          good:this.data.good
        })
      },
      changePropertyDefault(e) { //改变默认属性值
        let index = e.currentTarget.dataset.index
        let key = e.currentTarget.dataset.key
        this.data.good.property[index].values.forEach(value => {
          value.is_default = false
        })
        this.data.good.property[index].values[key].is_default = true
        if(this.data.judgeSame == this.data.good.property[index].values[key].value ){
          this.data.good.property[index].values.forEach(value => {
            value.is_default = false
          })
          this.data.judgeSame = ""
        }else {
          this.data.judgeSame = this.data.good.property[index].values[key].value
        }
        this.data.good.number = 1
        let product = Object.assign({}, this.data.good, {props_text: this.getGoodSelectedProps(this.data.good), props: this.getGoodSelectedProps(this.data.good, 'id')})
        let props_text =product.props_text.replace(/，/g, "");
        let  AllSpec = []
        this.data.products.forEach(item=>{
          if(item.spec == props_text ){
            this.data.good.images = item.thumbnail
          }
          AllSpec.push(item.spec)
        })
        let exisSpec=AllSpec.indexOf( props_text );
        if (exisSpec == -1) {
          this.data.addCartButton = false
        }else {
          this.data.addCartButton = true
        }
        this.setData({
          good:this.data.good,
          addCartButton:this.data.addCartButton
        })
      },
      handleAddToCartInModal() {
        var outOfstock = false
        let product = Object.assign({}, this.data.good, {props_text: this.getGoodSelectedProps(this.data.good), props: this.getGoodSelectedProps(this.data.good, 'id')})
        let props_text =product.props_text.replace(/，/g, "");
        let selectProduct =[]
        product.property.forEach(item=>{
          item.values.forEach(itemValues=>{
            selectProduct.push(itemValues.is_default)
          })
        })
        let existenceSelectProduct=selectProduct.indexOf( true );
        if( existenceSelectProduct == -1 ){
          wx.showToast({
            title: '请选择商品规格',
            duration: 2000,
            icon:'none'
          })
          return false
        }
        this.data.products.forEach(item=>{
          if(item.spec == props_text && item.stock != 0){
            outOfstock = true
            product.id= item.id
            let  params ={
              currentTarget:{
                dataset:{
                  item:this.data.category,
                  good:product,
                  num:this.data.good.number
                }
              }
            }
            this.handleAddToCart(params)
            this.closeGoodDetailModal()
          }
        })
        if(outOfstock == false){
          wx.showToast({
            icon: "none",
            title: '商品暂时缺货请重新选择',
            duration: 1000
          })}
      },
      getGoodSelectedProps(good, type = 'text') {	//计算当前饮品所选属性
        if(good.use_property) {
          let props = []
          if(Array.isArray(good.property)){
            good.property.forEach(({values}) => {
              values.forEach(value => {
                if(value.is_default) {
                  props.push(type === 'text' ? value.value : value.id)
                }
              })
            })
          }
          return type === 'text' ? props.join('，') : props
        }
        return ''
      },
      handlePropertyAdd() {
        this.data.good.number += 1
      },
      handlePropertyReduce() {
        if(this.data.good.number === 1) return
        this.data.good.number -= 1
      },
      openCartPopup() {	//打开/关闭购物车列表popup
        this.data.cartPopupVisible = !this.data.cartPopupVisible
        this.setData({
          cartPopupVisible:this.data.cartPopupVisible
        })

         this.selectComponent('#bottomPop').clickme();
      },
      handleCartClear() {	//清空购物车
        wx.showModal({
          title: '提示',
          content: '确定清空购物车么',
          success: ({confirm}) =>  {
            if(confirm) {
              new Promise((resolve, reject) => {
                this.data.cartPopupVisible = false
                let params ={}
                clear(params).then(res => {
                  resolve();
                })
              }).then(()=>{
                this.selectComponent('#bottomPop').clickme();
                this.data.cart = []
                this.data.goods.forEach(goodsItem=>{
                  goodsItem.goods_list.forEach(goodsListItem=>{
                    goodsListItem.number = 0
                  })
                })
                this.data.cartGoodsPrice = this.getCartGoodsPrice()
                this.data.cartGoodsNumber = this.getCartGoodsNumber()
                this.setData({
                  cart:this.data.cart,
                  goods:this.data.goods,
                  cartGoodsPrice:this.data.cartGoodsPrice,
                  cartGoodsNumber:this.data.cartGoodsNumber
                })
              })
            }
          }
        })
      },
      leaveEmptyShopping(){
        if(this.data.cart.length>0){
          new Promise((resolve, reject) => {
            this.data.cartPopupVisible = false
            let params =[]
            this.data.cart.forEach(item=>{
              params.push(item.id)
            })
            del(params.join(",")).then(res => {
              resolve() ;
            })
          }).then(()=>{
            this.data.cart = []
          })
        }
      },
      handleCartItemAdd(e) {
        let index = e.currentTarget.dataset.index
        let item = e.currentTarget.dataset.item
        new Promise((resolve, reject) => {
          this.numAdd(item,resolve, reject)
        }).then(()=>{
          this.data.cart[index].number += 1
          this.data.cartGoodsPrice = this.getCartGoodsPrice()
          this.data.cartGoodsNumber = this.getCartGoodsNumber()
          this.data.spread = this.getSpread()
          this.data.disabledPayFlag = this.getDisabledPay()
          console.log(this.data.disabledPayFlag ,"disabledPayFlagdisabledPayFlagdisabledPayFlag")
          this.setData({
            cart: this.data.cart,
            cartGoodsPrice:this.data.cartGoodsPrice,
            cartGoodsNumber:this.data.cartGoodsNumber,
            spread:this.data.spread,
            disabledPayFlag:this.data.disabledPayFlag
          })
        })
      },
      numAdd (item,resolve, reject) {
        let params =[{
          chk:true,
          id:item.id,
          quantity:item.number + 1
        }]
        update(params).then(res => {
          resolve() ;
        })
      },
      toPay() {
        if(app.globalData.token == null || app.globalData.token == '') {
          wx.navigateTo({
            url: '/pages/login/index',
          })
          return
        }
        if(this.data.spread >= 0 ){
            return false
        }
        wx.navigateTo({
          url: '/pages/goods/submit/index?shopId=' + this.data.shopId + '&orderType=' +this.data.orderType,
        })
      },

})